﻿using System;

namespace FB.Annotations
{
    [AttributeUsage(AttributeTargets.All)]
    public class LocalizedDescriptionAttribute : Attribute
    {
        public Type ResourceType { get; set; }
        public string Name { get; set; }
        public string Description { get { return GetDescription(); } }

        public LocalizedDescriptionAttribute() { }
        public LocalizedDescriptionAttribute(Type resourceType, string name)
        {
            ResourceType = resourceType;
            Name = name;
        }


        string GetDescription()
        {
            var desc = string.Empty;

            if (!string.IsNullOrEmpty(Name) && ResourceType != null)
            {
                System.Resources.ResourceManager rm = new System.Resources.ResourceManager(ResourceType);
                desc = rm.GetString(Name);
            }

            return desc;
        }

    }
}
